Uncaught TypeError: Property 'dist2' of object [object Object] is not a function

Posted by Radu Vlad on Stack Overflow See other posts from Stack Overflow or by Radu Vlad
Published on 2013-10-20T03:52:03Z Indexed on 2013/10/20 3:53 UTC
Read the original article Hit count: 106

Filed under:
|

I have this functions that should return me the distance from point p to segment line v-w. The problem i have is after some time i receive the following error: Uncaught TypeError: Property 'dist2' of object [object Object] is not a function.

I receive it in distToSegmentSquared directly,not even calling the function dist2().Is it any other dist2() anywhere in jquery?I found none...

       function sqr(x) {
            return x * x;
        }

        function dist2(v, w) {
            console.log(v);
            console.log(w);
            return sqr(v.x - w.x) + sqr(v.y - w.y);
        }

        function distToSegmentSquared(p, v, w) {
            var l2 = dist2(v, w);
            if (l2 == 0)
                return dist2(p, v);
            var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
            if (t < 0)
                return dist2(p, v);
            if (t > 1)
                return dist2(p, w);
            return dist2(p, {x: v.x + t * (w.x - v.x),
                y: v.y + t * (w.y - v.y)});
        }

        function distToSegment(p, v, w) {
            return Math.sqrt(distToSegmentSquared(p, v, w));
        }

The values that are given in for that error are:

p: Object
x: 461
y: 333

v: Object
x: 80
y: 120

w: Object
x: 260
y: 120

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery